﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Sofire.AOP.Settings
{
    internal class AOPHandlerSetting : AOPFilterSetting
    {
        internal AOPHandlerSetting() { }

        public AOPHandlerSetting(string name, HandlerObjectMode mode, Type type)
            :base(name,type)
        {
            this._Mode = mode;
        }

        private HandlerObjectMode _Mode;
        public HandlerObjectMode Mode
        {
            get
            {
                return this._Mode;
            }
        }

        internal override void OnLoad(XmlNode node)
        {
            base.OnLoad(node);
            var attrValue = node.TryGetAttribute("Mode");

            if(attrValue == string.Empty || string.Equals(attrValue, "SingleCall", StringComparison.OrdinalIgnoreCase))
                this._Mode = HandlerObjectMode.SingleCall;
            else if(string.Equals(attrValue, "Singleton", StringComparison.OrdinalIgnoreCase))
                this._Mode = HandlerObjectMode.Singleton;

            else throw new ArgumentException("无法识别 " + this.Name + " 处理器的实例模式值 " + attrValue + " ！", "Mode");

        }
    }
}
